<template>
    <div class="ma-content-block lg:flex justify-between p-4">
      <!-- CRUD 组件 -->
      <ma-crud :options="options" :columns="columns" ref="crudRef">
        <template #status="{record}">
          <a-tag :color="record?.status == 1?'blue':'gray'">{{ record?.status == 1?'正常':'禁用' }}</a-tag>
        </template>
      </ma-crud>
    </div>
  </template>
  <script setup>
  import { ref, reactive, } from 'vue'
  import predictionBanzu from '@/api/prediction/predictionBanzu'
  import { Message } from '@arco-design/web-vue'
  import tool from '@/utils/tool'
  import * as common from '@/utils/common'
  
  const crudRef = ref()
  
  
  const numberOperation = (newValue, id, numberName) => {
    predictionBanzu.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
      res.success && Message.success(res.message)
    }).catch( e => { console.log(e) } )
  }
  
  const switchStatus = (statusValue, id, statusName) => {
    predictionBanzu.changeStatus({ id, statusName, statusValue }).then( res => {
      res.success && Message.success(res.message)
    }).catch( e => { console.log(e) } )
  }
  
  
  const options = reactive({
    id: 'flyos_prediction_banzu',
    rowSelection: {
      showCheckedAll: true
    },
    pk: 'id',
    operationColumn: true,
    operationWidth: 160,
    formOption: {
      viewType: 'modal',
      width: 600
    },
    api: predictionBanzu.getList,
    recycleApi: predictionBanzu.getRecycleList,
    add: {
      show: true,
      api: predictionBanzu.save,
      auth: ['prediction:banzu:save']
    },
    edit: {
      show: true,
      api: predictionBanzu.update,
      auth: ['prediction:banzu:update']
    },
    delete: {
      show: true,
      api: predictionBanzu.deletes,
      auth: ['prediction:banzu:delete'],
      realApi: predictionBanzu.realDeletes,
      realAuth: ['prediction:banzu:realDeletes']
    },
    recovery: {
      show: true,
      api: predictionBanzu.recoverys,
      auth: ['prediction:banzu:recovery']
    },
    import: {
      show: true,
      url: 'prediction/banzu/import',
      templateUrl: 'prediction/banzu/downloadTemplate',
      auth: ['prediction:banzu:import']
    },
    export: {
      show: true,
      url: 'prediction/banzu/export',
      auth: ['prediction:banzu:export']
    }
  })
  
  const columns = reactive([
    {
      title: "",
      dataIndex: "id",
      formType: "input",
      addDisplay: false,
      editDisplay: false,
      hide: true,
      commonRules: {
        required: true,
        message: "请输入"
      }
    },
    {
      title: "班组名称",
      dataIndex: "name",
      formType: "input",
      search: true
    },
    {
      title: "状态",
      dataIndex: "status",
      formType: "switch",
      search: true,
      checkedValue: "1",
      uncheckedValue: "0"
    },
    {
      title: "备注",
      dataIndex: "remark",
      formType: "input",
    },
    {
      title: "创建时间",
      dataIndex: "created_at",
      formType: "date",
      addDisplay: false,
      editDisplay: false,
      showTime: true
    },
    {
      title: "更新时间",
      dataIndex: "updated_at",
      formType: "date",
      addDisplay: false,
      editDisplay: false,
      hide: true,
      showTime: true
    },
  ])

  defineExpose({ open });
  </script>
  <script> export default { name: 'prediction:peisong' } </script>